﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class UIVAKDBEZ : ViewBase
    {

        TSSD0561 c561
        {
            get
            {
                return (TSSD0561)this.FindName("cTSSD0561");
            }
        }

        public UIVAKDBEZ()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
        }


        public override void Window_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
            ((VVAKDBEZ)MV).STUVAKDBEZ();
        }



        public void GetColorNo(object sender, RoutedEventArgs e)
        {
            if (c561 == null)
                return;
            while (true)
            {
                string _FARBE = c561.GetColorNo();
                
                string a = ""; 
                if (_FARBE.Substring(0, 3).Contains("YGW"))
                {
                    a = Helper.Right("0000"+_FARBE.Substring(3).Trim(),4);
                    _FARBE = "YGW" + a;
                    _FARBE = Helper.Left(_FARBE.PadRight(7), 7);
                }
                if (_FARBE.Substring(0, 3).Contains("YRW"))
                {
                    a = Helper.Right("0000" + _FARBE.Substring(3).Trim(), 4);
                    _FARBE = "YRW" + a;
                    _FARBE = Helper.Left(_FARBE.PadRight(7), 7);
                }
                DataRow dwVAF = TMV.VAF.TBMain.NewRow();
                dwVAF["VAFART"] = Helper.Left(_FARBE.PadRight(24), 24);
                SResult = TMV.VAF.QVAF12(dwVAF);
                if (SResult.Tables[0].Rows.Count == 0)
                {
                    FARBE = _FARBE;
                    TMV.InsertCOLOR(FARBE);
                    break;
                }
            }

            IsGetNo = true;
        }

       
    }
    public partial class UIVAKDBEZ : ViewBase
    {
        public VVAKDBEZ TMV
        {
            get
            {
                return (VVAKDBEZ)MV;
            }
        }
        #region ==dwSD561===========
        public static readonly DependencyProperty dwSD561Property = DependencyProperty.Register("dwSD561",
            typeof(DataRow), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwSD561Changed));
        public DataRow dwSD561
        {
            get
            {
                return (DataRow)GetValue(dwSD561Property);
            }
            set
            {
                SetValue(dwSD561Property, value);
                OnSD561Chg(value);
            }
        }
        private static void OndwSD561Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAKDBEZ;
            if (src != null)
            {
                src.dwSD561 = (DataRow)e.NewValue;

            }
        }
        public virtual void OnSD561Chg(DataRow dw)
        {
            if (dwVAK == null)
                return;
            if (dwSD561 == null)
                return;
            FARBE = dwSD561["SDES"].ToString();
            FARBGRP = dwSD561["KEY"].ToString();

        }
        #endregion

        #region ==FARBGRP===========
        public static readonly DependencyProperty FARBGRPProperty = DependencyProperty.Register("FARBGRP",
            typeof(string), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFARBGRPChanged));
        public string FARBGRP
        {
            get
            {
                return (string)GetValue(FARBGRPProperty);
            }
            set
            {
                SetValue(FARBGRPProperty, value);
            }
        }
        private static void OnFARBGRPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAKDBEZ;
            src.FARBGRP = (string)e.NewValue;

        }
        #endregion

        #region ==dwKD===========
        public static readonly DependencyProperty dwKDProperty = DependencyProperty.Register("dwKD",
            typeof(DataRow), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwKDChanged));
        public DataRow dwKD
        {
            get
            {
                return (DataRow)GetValue(dwKDProperty);
            }
            set
            {
                SetValue(dwKDProperty, value);
                if (dwVAK == null)
                    return;
                KUNDNR = value["KDKUNDNR"].ToString();
            }
        }
        private static void OndwKDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAKDBEZ;
            if (src != null)
            {
                src.dwKD = (DataRow)e.NewValue;

            }
        }
        #endregion

        #region ==KDFARBNR===========
        public static readonly DependencyProperty KDFARBNRProperty = DependencyProperty.Register("KDFARBNR",
            typeof(string), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDFARBNRChanged));
        public string KDFARBNR
        {
            get
            {
                return (string)GetValue(KDFARBNRProperty);
            }
            set
            {
                SetValue(KDFARBNRProperty, value);
            }
        }
        private static void OnKDFARBNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAKDBEZ;
            src.KDFARBNR = (string)e.NewValue;

        }
        #endregion

        #region ==IsKDFound===========
        public static readonly DependencyProperty IsKDFoundProperty = DependencyProperty.Register("IsKDFound",
            typeof(bool), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsKDFoundChanged));
        public bool IsKDFound
        {
            get
            {
                return (bool)GetValue(IsKDFoundProperty);
            }
            set
            {
                SetValue(IsKDFoundProperty, value);
            }
        }
        private static void OnIsKDFoundChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAKDBEZ;
            if (src != null)
            {
                src.IsKDFound = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsCopy===========
        public static readonly DependencyProperty IsCopyProperty = DependencyProperty.Register("IsCopy",
            typeof(bool), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCopyChanged));
        public bool IsCopy
        {
            get
            {
                return (bool)GetValue(IsCopyProperty);
            }
            set
            {
                SetValue(IsCopyProperty, value);
            }
        }
        private static void OnIsCopyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAKDBEZ;
            if (src != null)
            {
                src.IsCopy = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsGSSave===========
        public static readonly DependencyProperty IsGSSaveProperty = DependencyProperty.Register("IsGSSave",
            typeof(bool), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsGSSaveChanged));
        public bool IsGSSave
        {
            get
            {
                return (bool)GetValue(IsGSSaveProperty);
            }
            set
            {
                SetValue(IsGSSaveProperty, value);

            }
        }
        private static void OnIsGSSaveChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAKDBEZ;
            if (src != null)
            {
                src.IsGSSave = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==ISAVE===========
        public static readonly DependencyProperty ISAVEProperty = DependencyProperty.Register("ISAVE",
            typeof(bool), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnISAVEChanged));
        public bool ISAVE
        {
            get
            {
                return (bool)GetValue(ISAVEProperty);
            }
            set
            {
                SetValue(ISAVEProperty, value);

            }
        }
        private static void OnISAVEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAKDBEZ;
            if (src != null)
            {
                src.ISAVE = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsGetNo===========
        public static readonly DependencyProperty IsGetNoProperty = DependencyProperty.Register("IsGetNo",
            typeof(bool), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsGetNoChanged));
        public bool IsGetNo
        {
            get
            {
                return (bool)GetValue(IsGetNoProperty);
            }
            set
            {
                SetValue(IsGetNoProperty, value);
            }
        }
        private static void OnIsGetNoChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAKDBEZ;
            if (src != null)
            {
                src.IsGetNo = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsXJNew===========
        public static readonly DependencyProperty IsXJNewProperty = DependencyProperty.Register("IsXJNew",
            typeof(bool), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsXJNewChanged));
        public bool IsXJNew
        {
            get
            {
                return (bool)GetValue(IsXJNewProperty);
            }
            set
            {
                SetValue(IsXJNewProperty, value);
            }
        }
        private static void OnIsXJNewChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAKDBEZ;
            if (src != null)
            {
                src.IsXJNew = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==KUNDNR===========
        public static readonly DependencyProperty KUNDNRProperty = DependencyProperty.Register("KUNDNR",
            typeof(string), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKUNDNRChanged));
        public string KUNDNR
        {
            get
            {
                return (string)GetValue(KUNDNRProperty);
            }
            set
            {
                SetValue(KUNDNRProperty, value);
                if (value == "")
                {
                    IsKDFound = true;
                }
                else
                {
                    IsKDFound = false;
                }
            }
        }
        private static void OnKUNDNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAKDBEZ;
            src.KUNDNR = (string)e.NewValue;

        }
        #endregion

        #region ==KDKUNDNA===========
        public static readonly DependencyProperty KDKUNDNAProperty = DependencyProperty.Register("KDKUNDNA",
            typeof(string), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDKUNDNAChanged));
        public string KDKUNDNA
        {
            get
            {
                return (string)GetValue(KDKUNDNAProperty);
            }
            set
            {
                SetValue(KDKUNDNAProperty, value);
            }
        }
        private static void OnKDKUNDNAChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAKDBEZ;
            src.KDKUNDNA = (string)e.NewValue;

        }
        #endregion

        #region ==CGRP===========
        public static readonly DependencyProperty CGRPProperty = DependencyProperty.Register("CGRP",
            typeof(string), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCGRPChanged));
        public string CGRP
        {
            get
            {
                return (string)GetValue(CGRPProperty);
            }
            set
            {
                SetValue(CGRPProperty, value);
                OnCGRPChg(value);
            }
        }
        private static void OnCGRPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var source = sender as UIVAKDBEZ;
            if (source != null)
            {
                source.CGRP = (string)e.NewValue;
            }
        }
        public virtual void OnCGRPChg(string value)
        { }
        #endregion

        #region ==CR===========
        public static readonly DependencyProperty CRProperty = DependencyProperty.Register("CR",
            typeof(string), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata("0", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCRChanged));
        public string CR
        {
            get
            {
                return (string)GetValue(CRProperty);
            }
            set
            {
                SetValue(CRProperty, value);
                if (!IsEdit)
                    return;
                if (dwMaster == null)
                    return;

                dwMaster["CR"] = value;
            }
        }
        private static void OnCRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var source = sender as UIVAKDBEZ;
            if (source != null)
            {
                source.CR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==CG===========
        public static readonly DependencyProperty CGProperty = DependencyProperty.Register("CG",
            typeof(string), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata("0", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCGChanged));
        public string CG
        {
            get
            {
                return (string)GetValue(CGProperty);
            }
            set
            {
                SetValue(CGProperty, value);
                if (!IsEdit)
                    return;
                if (dwMaster == null)
                    return;
                dwMaster["CG"] = value;
            }
        }
        private static void OnCGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var source = sender as UIVAKDBEZ;
            if (source != null)
            {
                source.CG = (string)e.NewValue;
            }
        }
        #endregion

        #region ==CB===========
        public static readonly DependencyProperty CBProperty = DependencyProperty.Register("CB",
            typeof(string), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata("0", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCBChanged));
        public string CB
        {
            get
            {
                return (string)GetValue(CBProperty);
            }
            set
            {
                SetValue(CBProperty, value);
                if (!IsEdit)
                    return;
                if (dwMaster == null)
                    return;
                dwMaster["CB"] = value;
            }
        }
        private static void OnCBChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var source = sender as UIVAKDBEZ;
            if (source != null)
            {
                source.CB = (string)e.NewValue;
            }
        }
        #endregion

        #region ==VAFBEZ===========
        public static readonly DependencyProperty VAFBEZProperty = DependencyProperty.Register("VAFBEZ",
            typeof(string), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata("     ", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVAFBEZChanged));
        public string VAFBEZ
        {
            get
            {
                return (string)GetValue(VAFBEZProperty);
            }
            set
            {
                SetValue(VAFBEZProperty, value);
                if (!IsEdit)
                    return;
                if (dwVAK == null)
                    return;
                dwVAK["VAFBEZ"] = value;
            }
        }
        private static void OnVAFBEZChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var source = sender as UIVAKDBEZ;
            if (source != null)
            {
                source.VAFBEZ = (string)e.NewValue;
            }
        }
        #endregion

        #region ==dwVAK===========
        public static readonly DependencyProperty dwVAKProperty = DependencyProperty.Register("dwVAK",
            typeof(DataRow), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwVAKChanged));
        public DataRow dwVAK
        {
            get
            {
                return (DataRow)GetValue(dwVAKProperty);
            }
            set
            {
                SetValue(dwVAKProperty, value);
            }
        }
        private static void OdwVAKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAKDBEZ;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwVAK = row;
            }
        }
        #endregion

        #region ==TBMAT===========
        public static readonly DependencyProperty TBMATProperty = DependencyProperty.Register("TBMAT",
            typeof(DataTable), typeof(UIVAKDBEZ),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OTBMATChanged));
        public DataTable TBMAT
        {
            get
            {
                return (DataTable)GetValue(TBMATProperty);
            }
            set
            {
                SetValue(TBMATProperty, value);
            }
        }
        private static void OTBMATChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVAKDBEZ;
            if (src != null)
            {
                src.TBMAT = (DataTable)e.NewValue;
            }
        }
        #endregion
    }
}
